﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.WebPages
{
    public partial class Details : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        //protected string menuName = string.Empty;
        //protected string subMenuName = string.Empty;
        //protected string parentCategoryStr = string.Empty;
        //protected string categoryStr = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            byte parentCategory = byte.Parse(Request.QueryString["parentCategory"]);
            byte category = byte.Parse(Request.QueryString["categories"]);
            SubMenu pmenu = db.SubMenu.FirstOrDefault(s => s.Categories == parentCategory);
            SubMenu smenu = db.SubMenu.FirstOrDefault(s => s.Categories == category);

            hlpmenu.NavigateUrl = pmenu.LinkUrl;
            hlpmenu.Text = pmenu.Name;
            hlsmenu.NavigateUrl = smenu.LinkUrl;
            hlsmenu.Text = smenu.Name;

            long articleID = long.Parse(Request.QueryString["articleid"]);

            var article = db.Article.FirstOrDefault(a => a.ArticleID == articleID);
            if (article != null)
            {
                article.ReadTimes += 1;
                db.SaveChanges();

                lblTime.Text = article.UpdateTime.Value.ToString("yyyy年MM月dd日");
                lblReadTimes.Text = article.ReadTimes.ToString();
                lblTitle.Text = article.Title;
                ltlContent.Text = article.Content;
            }

            var attachments = db.Attachment.Where(a => a.Article.ArticleID == articleID);
            if (attachments.Count() > 0)
            {
                attachmentContainer.Visible = true;

                rep_attachment.DataSource = attachments;
                rep_attachment.DataBind();
            }
        }
    }
}
